<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>商城系统</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="${request.contextPath}/plug/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="${request.contextPath}/css/febs.css" media="all">
    <link rel="stylesheet" href="${request.contextPath}/css/login.css" media="all">
</head>
<body>
<div id="febs-login" lay-title="登录">
    <div class="login-wrap">
        <div class="layui-container">
            <div class="layui-row">
                <div class="layui-col-xs12 layui-col-lg4 layui-col-lg-offset4 febs-tc">
                    <div class="layui-logo"><span><b>商城系统</b></span></div>
                </div>
                <div class="layui-col-xs12 layui-col-lg4 layui-col-lg-offset4" id="login-div">
                    <div class="layui-form" lay-filter="login-form">
                        <div class="layui-anim layui-anim-upbit">
                            <ul class="login-type-tab">
                                <li class="active">系统登录</li>
                            </ul>
                            <div class="normal-login-form">
                                <div class="layui-form-item">
                                    <label class="layui-icon label-icon layui-icon-username"></label>
                                    <input type="text" name="username" lay-verify="required"
                                           placeholder="用户名" autocomplete="off" class="layui-input" id="username">
                                </div>
                                <div class="layui-form-item password-block">
                                    <label class="layui-icon label-icon layui-icon-password"></label>
                                    <input type="password" name="password" lay-verify="required"
                                           placeholder="密码" autocomplete="off" class="layui-input" id="password">
                                </div>
                                <div class="layui-form-item">
                                    <div class="layui-row">
                                        <div class="layui-col-xs7">
                                            <label class="layui-icon label-icon layui-icon-vercode"></label>
                                            <input type="text" maxlength="4" name="verifyCode" lay-verify="required"
                                                   placeholder="验证码" class="layui-input" autocomplete="off"
                                                   id="verifyCode">
                                        </div>
                                        <div class="layui-col-xs5">
                                            <img class="codeimg" id="codeimg"/>
                                        </div>
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <button class="layui-btn layui-btn-normal layui-btn-fluid" id="login">
                                        <i style="display: none"
                                           class="layui-icon layui-icon-loading layui-icon layui-anim layui-anim-rotate layui-anim-loop"></i>
                                        立即登录
                                    </button>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script src="${request.contextPath}/js/jquery.min.js"></script>
<script src="${request.contextPath}/js/layer.js"></script>
<script>
    var ctx = '${request.contextPath}';
    $(function(){
      initCode();
    });
    function initCode() {
            $('#codeimg').attr("src", ctx + "images/captcha?data=" + new Date().getTime());
     }

    $('#codeimg').on('click', function () {
        initCode();
    });

    $('#login').on('click',function(){
        var username=$("#username").val();
        var password=$("#password").val();
        var verifyCode=$("#verifyCode").val();
        if($.trim(username) == ""){
            layer.msg("用户名不能为空！")
            return;
        }
        if($.trim(password) == ""){
            layer.msg("密码不能为空！")
            return;
        }
        if($.trim(verifyCode) == ""){
            layer.msg("验证码不能为空！")
            return;
        }
        var loginObj = new Object();
        loginObj["userName"] = username;
        loginObj["password"] = password;
        loginObj["verifyCode"] = verifyCode;
        $.ajax({
                      type: 'POST',
                      url: ctx+'/admin/login',
                      data: JSON.stringify(loginObj),
                      dataType:'json',
                      contentType:'application/json',
                      success: function(data){
                          if(typeof(data) == 'string'){
                            data = JSON.parse(data);
                          }
                          if(data.code==200){
                             window.location.href=ctx+"/admin/index"
                          }else{
                             layer.msg(data.msg)
                              initCode();
                          }
                      },

                    });
    });

    $(document).on('keydown', function (e) {
        if (e.keyCode === 13) {
                $('#login').click();
        }
    });

</script>
</body>
</html>